home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODMisc / SLSUSink.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  13.7 KB  |  495 lines  |  [TEXT/MPS ]

  1. //
  2. //    File:                SLSUSink.cpp
  3. //    Release Version:    $ ODF 2 $
  4. //
  5. //    Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  6. //
  7.  
  8. #include "FWOS.hpp"
  9.  
  10. #ifndef FWSTDDEF_H
  11. #include "FWStdDef.h"
  12. #endif
  13.  
  14. #ifndef FWBARRAY_H
  15. #include "FWBArray.h"
  16. #endif
  17.  
  18. #ifndef FWPRIDEB_H
  19. #include "FWPriDeb.h"
  20. #endif
  21.  
  22. #ifndef FWEXCEPT_H
  23. #include "FWExcept.h"
  24. #endif
  25.  
  26. // ----- OpenDoc Includes -----
  27.  
  28. #ifndef SOM_ODStorageUnit_xh
  29. #include <StorageU.xh>
  30. #endif
  31.  
  32. #ifndef SOM_ODStorageUnitView_xh
  33. #include <SUView.xh>
  34. #endif
  35.  
  36. // ----- Platform Includes -----
  37.  
  38. #if defined(FW_BUILD_MAC) & !defined(SOMCorba_h)
  39. #include <somcorba.h>
  40. #endif
  41.  
  42.  
  43. /*
  44.  *  This file was generated by the SOM Compiler.
  45.  *  Generated using: 
  46.  *      SOM Emitter emitxtm.dll: 2.33
  47.  */
  48.  
  49. #define FW_OStorageUnitSink_Class_Source
  50. #include "SLSUSink.xih"
  51.  
  52.  
  53. //========================================================================================
  54. //    RunTime Info
  55. //========================================================================================
  56.  
  57. #ifdef FW_BUILD_MAC
  58. #pragma segment fwodmisc
  59. #endif
  60.  
  61. //========================================================================================
  62. //    CLASS FW_CPrivSUSinkRep
  63. //========================================================================================
  64.  
  65. class FW_CPrivSUSinkRep
  66. {
  67. public:
  68.     FW_DECLARE_AUTO(FW_CPrivSUSinkRep)
  69.  
  70.     FW_CPrivSUSinkRep(Environment* ev, 
  71.                       ODStorageUnitView* storageUnitView);
  72.     FW_CPrivSUSinkRep(Environment* ev, 
  73.                       ODStorageUnit* storageUnit, 
  74.                       ODPropertyName propertyName, 
  75.                       ODValueType valueType);
  76.  
  77.     ~FW_CPrivSUSinkRep();
  78.  
  79. public:
  80.     // ----- Random Access Sink Protocol
  81.     long  GetPosition(Environment* ev);
  82.     void  SetPosition(Environment* ev, long position);
  83.     long  GetLength(Environment* ev);
  84.     void  SetLength(Environment* ev, long length);
  85.  
  86.     void  Read(Environment* ev, void* destination, long count);
  87.     
  88.     long  GetWritableBytes(Environment* ev);
  89.     void  Write(Environment* ev, void* source, long count);
  90.  
  91. public:
  92.     void  Acquire(Environment* ev);
  93.  
  94. public:
  95.     ODStorageUnitView*        fStorageUnitView;
  96.     FW_Boolean                fOwnsView;
  97. };
  98.  
  99. FW_DEFINE_AUTO(FW_CPrivSUSinkRep)
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    FW_CPrivSUSinkRep::FW_CPrivSUSinkRep
  103. //----------------------------------------------------------------------------------------
  104.  
  105. FW_CPrivSUSinkRep::FW_CPrivSUSinkRep(Environment* ev, 
  106.                                      ODStorageUnitView* storageUnitView) :
  107.     fStorageUnitView(storageUnitView), 
  108.     fOwnsView(FALSE)
  109. {
  110.     Acquire(ev);
  111.  
  112.     FW_END_CONSTRUCTOR
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. //    FW_CPrivSUSinkRep::FW_CPrivSUSinkRep
  117. //----------------------------------------------------------------------------------------
  118.  
  119. FW_CPrivSUSinkRep::FW_CPrivSUSinkRep(Environment* ev,
  120.                                      ODStorageUnit* storageUnit, 
  121.                                      ODPropertyName propertyName, 
  122.                                      ODValueType valueType) :
  123.     fStorageUnitView(0), 
  124.     fOwnsView(TRUE)
  125. {
  126.     FW_ASSERT(propertyName != NULL);
  127.     FW_ASSERT(valueType != NULL);
  128.     
  129.     storageUnit->Focus(ev, 
  130.                        propertyName, kODPosUndefined, 
  131.                        valueType, (ODValueIndex)0, kODPosUndefined);
  132.     fStorageUnitView = storageUnit->CreateView(ev);
  133.  
  134.     Acquire(ev);
  135.  
  136.     FW_END_CONSTRUCTOR
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    FW_CPrivSUSinkRep::~FW_CPrivSUSinkRep
  141. //----------------------------------------------------------------------------------------
  142.  
  143. FW_CPrivSUSinkRep::~FW_CPrivSUSinkRep()
  144. {
  145.     FW_START_DESTRUCTOR
  146.  
  147.     FW_SOMEnvironment ev;
  148.     
  149. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  150.     if (fStorageUnitView)
  151.         fStorageUnitView->GetStorageUnit(ev)->Release(ev);
  152. #endif
  153.  
  154.     if (fOwnsView)
  155.         delete fStorageUnitView;
  156. }
  157.  
  158.  
  159. //----------------------------------------------------------------------------------------
  160. //     FW_CPrivSUSinkRep::GetPosition
  161. //----------------------------------------------------------------------------------------
  162.  
  163. inline long FW_CPrivSUSinkRep::GetPosition(Environment* ev)
  164. {
  165.     return fStorageUnitView->GetOffset(ev);
  166. }
  167.  
  168.  
  169. //----------------------------------------------------------------------------------------
  170. //    FW_CPrivSUSinkRep::SetPosition
  171. //----------------------------------------------------------------------------------------
  172.  
  173. inline void FW_CPrivSUSinkRep::SetPosition(Environment* ev, long position)
  174. {
  175.     fStorageUnitView->SetOffset(ev, position);
  176. }
  177.  
  178.  
  179. //----------------------------------------------------------------------------------------
  180. //     FW_CPrivSUSinkRep::GetLength
  181. //----------------------------------------------------------------------------------------
  182.  
  183. inline long FW_CPrivSUSinkRep::GetLength(Environment* ev)
  184. {
  185.     // calling fStorageUnitView->GetSize(ev) results in a throw
  186.     return fStorageUnitView->GetStorageUnit(ev)->GetSize(ev);
  187. }
  188.  
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //     FW_CPrivSUSinkRep::SetLength
  192. //----------------------------------------------------------------------------------------
  193.  
  194. void FW_CPrivSUSinkRep::SetLength(Environment* ev, long length)
  195. {
  196.     long prevLength = GetLength(ev);
  197.  
  198.     if (length < prevLength)
  199.     {
  200.         SetPosition(ev, length);
  201.         fStorageUnitView->DeleteValue(ev, prevLength-length);
  202.     }
  203.     else if (length > prevLength)
  204.     {
  205.         const long kSize = 128;
  206.         char buffer[kSize] = {0};
  207.         SetPosition(ev, prevLength);
  208.         length -= prevLength;
  209.         while (length > 0)
  210.         {
  211.             long bytes = length < kSize ? length : kSize;
  212.             Write(ev, buffer, bytes);
  213.             length -= bytes;
  214.         }
  215.     }
  216. }
  217.  
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    FW_CPrivSUSinkRep::Read
  221. //----------------------------------------------------------------------------------------
  222.  
  223. inline void FW_CPrivSUSinkRep::Read(Environment* ev, void* destination, long count)
  224. {
  225. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  226.     FW_CByteArray    byteArray;
  227.  
  228.     fStorageUnitView->GetValue(ev, count, byteArray);
  229.     byteArray.CopyBuffer(destination, count);
  230. #elif FW_OPENDOC_VERSION == FW_OPENDOC_DR2
  231.     FW_CByteArray    byteArray(destination, count);
  232.  
  233.     fStorageUnitView->GetValue(ev, byteArray);
  234. #else
  235.     fStorageUnitView->GetValue(ev, count, destination);
  236. #endif
  237. }
  238.  
  239.  
  240. //----------------------------------------------------------------------------------------
  241. //    FW_CPrivSUSinkRep::GetWritableBytes
  242. //----------------------------------------------------------------------------------------
  243.  
  244. long FW_CPrivSUSinkRep::GetWritableBytes(Environment* ev)
  245. {
  246. FW_UNUSED(ev);
  247.     return 0x7FFFFFFFL;
  248. }
  249.  
  250.  
  251. //----------------------------------------------------------------------------------------
  252. //    FW_CPrivSUSinkRep::Write
  253. //----------------------------------------------------------------------------------------
  254.  
  255. void FW_CPrivSUSinkRep::Write(Environment* ev, void* source, long count)
  256. {
  257. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR2
  258.     FW_CByteArray    byteArray(source, count);
  259.     
  260.     fStorageUnitView->SetValue(ev, byteArray);
  261. #else
  262.     fStorageUnitView->SetValue(ev, count, source);
  263. #endif
  264. }
  265.  
  266.  
  267. //----------------------------------------------------------------------------------------
  268. //    FW_CPrivSUSinkRep::Acquire
  269. //----------------------------------------------------------------------------------------
  270.  
  271. void FW_CPrivSUSinkRep::Acquire(Environment* ev)
  272. {
  273. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  274.     if (fStorageUnitView)
  275.         fStorageUnitView->GetStorageUnit(ev)->Acquire(ev);
  276. #endif
  277. }
  278.  
  279.  
  280. //----------------------------------------------------------------------------------------
  281. // FW_OStorageUnitSink__InitFromStorageUnitView
  282. //----------------------------------------------------------------------------------------
  283.  
  284. /*
  285.  *  Create a sink attached to the storage unit view.
  286.  *  The sink does not assume ownership of the view.
  287.  */
  288.  
  289. SOM_Scope void  SOMLINK FW_OStorageUnitSink__InitFromStorageUnitView(FW_OStorageUnitSink *somSelf, Environment *ev,
  290.         ODStorageUnitView* storageUnitView)
  291. {
  292.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  293.  
  294.     FW_SOM_TRY
  295.     {
  296.         somThis->fRep = FW_NEW(FW_CPrivSUSinkRep, (ev, storageUnitView));
  297.     }
  298.     FW_SOM_CATCH
  299. }
  300.  
  301.  
  302. //----------------------------------------------------------------------------------------
  303. // FW_OStorageUnitSink__InitFromStorageUnitAndProperty
  304. //----------------------------------------------------------------------------------------
  305.  
  306. /*
  307.  *  Create a sink attached to the given (storageUnit, propertyName, valueType).
  308.  */
  309.  
  310. SOM_Scope void  SOMLINK FW_OStorageUnitSink__InitFromStorageUnitAndProperty(FW_OStorageUnitSink *somSelf, Environment *ev,
  311.         ODStorageUnit* storageUnit,
  312.         ODPropertyName propertyName,
  313.         ODValueType valueType)
  314. {
  315.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  316.  
  317.     FW_SOM_TRY
  318.     {
  319.         somThis->fRep = FW_NEW(FW_CPrivSUSinkRep, (ev, storageUnit, propertyName, valueType));
  320.     }
  321.     FW_SOM_CATCH
  322. }
  323.  
  324.  
  325. //----------------------------------------------------------------------------------------
  326. // FW_OStorageUnitSink__GetStorageUnitView
  327. //----------------------------------------------------------------------------------------
  328.  
  329. SOM_Scope ODStorageUnitView*  SOMLINK FW_OStorageUnitSink__GetStorageUnitView(FW_OStorageUnitSink *somSelf, Environment *ev)
  330. {
  331. FW_UNUSED(ev);
  332.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  333.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  334.  
  335.     return rep.fStorageUnitView;
  336. }
  337.  
  338.  
  339. //----------------------------------------------------------------------------------------
  340. // FW_OStorageUnitSink__somInit
  341. //----------------------------------------------------------------------------------------
  342.  
  343. SOM_Scope void  SOMLINK FW_OStorageUnitSink__somInit(FW_OStorageUnitSink *somSelf)
  344. {
  345. FW_UNUSED(somSelf);
  346. //    FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  347.  
  348. //    FW_OStorageUnitSink_parent_FW_ORandomAccessSink_somInit(somSelf);
  349. }
  350.  
  351.  
  352. //----------------------------------------------------------------------------------------
  353. // FW_OStorageUnitSink__somUninit
  354. //----------------------------------------------------------------------------------------
  355.  
  356. SOM_Scope void  SOMLINK FW_OStorageUnitSink__somUninit(FW_OStorageUnitSink *somSelf)
  357. {
  358.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  359.  
  360.     FW_SOM_UNINIT_TRY
  361.     {
  362.         delete somThis->fRep;
  363. //        FW_OStorageUnitSink_parent_FW_ORandomAccessSink_somUninit(somSelf);
  364.     }
  365.     FW_SOM_UNINIT_CATCH
  366. }
  367.  
  368.  
  369. //----------------------------------------------------------------------------------------
  370. // FW_OStorageUnitSink__Read
  371. //----------------------------------------------------------------------------------------
  372.  
  373. SOM_Scope void  SOMLINK FW_OStorageUnitSink__Read(FW_OStorageUnitSink *somSelf, Environment *ev,
  374.         void* destination,
  375.         long count)
  376. {
  377.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  378.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  379.  
  380.     FW_SOM_TRY
  381.     {
  382.         rep.Read(ev, destination, count);
  383.     }
  384.     FW_SOM_CATCH
  385. }
  386.  
  387.  
  388. //----------------------------------------------------------------------------------------
  389. // FW_OStorageUnitSink__GetWritableBytes
  390. //----------------------------------------------------------------------------------------
  391.  
  392. SOM_Scope long  SOMLINK FW_OStorageUnitSink__GetWritableBytes(FW_OStorageUnitSink *somSelf, Environment *ev)
  393. {
  394.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  395.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  396.  
  397.     FW_SOM_TRY
  398.     {
  399.         return rep.GetWritableBytes(ev);
  400.     }
  401.     FW_SOM_CATCH
  402.     return 0;
  403. }
  404.  
  405.  
  406. //----------------------------------------------------------------------------------------
  407. // FW_OStorageUnitSink__Write
  408. //----------------------------------------------------------------------------------------
  409.  
  410. SOM_Scope void  SOMLINK FW_OStorageUnitSink__Write(FW_OStorageUnitSink *somSelf, Environment *ev,
  411.         void* source,
  412.         long count)
  413. {
  414.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  415.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  416.  
  417.     FW_SOM_TRY
  418.     {
  419.         rep.Write(ev, source, count);
  420.     }
  421.     FW_SOM_CATCH
  422. }
  423.  
  424.  
  425. //----------------------------------------------------------------------------------------
  426. // FW_OStorageUnitSink__GetLength
  427. //----------------------------------------------------------------------------------------
  428.  
  429. SOM_Scope long  SOMLINK FW_OStorageUnitSink__GetLength(FW_OStorageUnitSink *somSelf, Environment *ev)
  430. {
  431.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  432.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  433.  
  434.     FW_SOM_TRY
  435.     {
  436.         return rep.GetLength(ev);
  437.     }
  438.     FW_SOM_CATCH
  439.     return 0;
  440. }
  441.  
  442.  
  443. //----------------------------------------------------------------------------------------
  444. // FW_OStorageUnitSink__SetLength
  445. //----------------------------------------------------------------------------------------
  446.  
  447. SOM_Scope void  SOMLINK FW_OStorageUnitSink__SetLength(FW_OStorageUnitSink *somSelf, Environment *ev,
  448.         long length)
  449. {
  450.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  451.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  452.  
  453.     FW_SOM_TRY
  454.     {
  455.         rep.SetLength(ev, length);
  456.     }
  457.     FW_SOM_CATCH
  458. }
  459.  
  460.  
  461. //----------------------------------------------------------------------------------------
  462. // FW_OStorageUnitSink__GetPosition
  463. //----------------------------------------------------------------------------------------
  464.  
  465. SOM_Scope long  SOMLINK FW_OStorageUnitSink__GetPosition(FW_OStorageUnitSink *somSelf, Environment *ev)
  466. {
  467.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  468.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  469.  
  470.     FW_SOM_TRY
  471.     {
  472.         return rep.GetPosition(ev);
  473.     }
  474.     FW_SOM_CATCH
  475.     return 0;
  476. }
  477.  
  478.  
  479. //----------------------------------------------------------------------------------------
  480. // FW_OStorageUnitSink__SetPosition
  481. //----------------------------------------------------------------------------------------
  482.  
  483. SOM_Scope void  SOMLINK FW_OStorageUnitSink__SetPosition(FW_OStorageUnitSink *somSelf, Environment *ev,
  484.         long position)
  485. {
  486.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  487.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  488.  
  489.     FW_SOM_TRY
  490.     {
  491.         rep.SetPosition(ev, position);
  492.     }
  493.     FW_SOM_CATCH
  494. }
  495.